import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
public class ShoppingCartServlet extends HttpServlet{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		HttpSession session = null;

		prettyPrint(0, out, "<table>");
		session = request.getSession();
		session.setMaxInactiveInterval(200);
		
		if(session!=null && session.getAttribute("products")!=null){
			String product = session.getAttribute("products").toString();

			prettyPrint(1, out, "<div id=\"boxContainer\">");
			prettyPrint(2, out, "<td>");
			prettyPrint(3, out, "<div class='boxHead'>Cart</div>");
			prettyPrint(2, out, "<div class='boxContent'>");
			prettyPrint(2, out, "<table width=155>");
			prettyPrint(3, out, "<tr>");
			prettyPrint(3, out, product);
			prettyPrint(4, out, "<td width=35 align=\"right\"><i>1000,-</i></td>");
			prettyPrint(5, out, "</tr>");
			prettyPrint(2, out, "</table></div></div>");

			prettyPrint(0, out, "</table>");
		}
	}

	private void prettyPrint(int tabs, PrintWriter outwriter, String output){
		for(int i = 0; i < tabs; i++){
			outwriter.print("\t");
		}
		outwriter.println(output);
	}
}